<?php
class Zuoye extends MY_Controller
{	
	function __construct() {
        parent::__construct();
    }

    function get_zuoye_reward(){
        $data = $this->user_post_data;
        if(!empty($data)){
            $child_id = $data['child_id'];
            $this->load->model('Zuoye_reward_model');
            $reward_list = $this->Zuoye_reward_model->get_reward($child_id);

            $data_obj = array(
                'count' => count($reward_list),
                'list' => $reward_list,
             );

        	echo json_encode(array("code" => 1, "data" => $data_obj));
        }else{
            echo json_encode(array("code" => 404, "data" => 'not user'));
        }
    }

    function add_reward(){
    	$data = $this->user_post_data;
        if(!empty($data)){
           
            $reward_data = array(
            	'user_id' => $data['user_token']['user_id'], 
            	'child_id' => $data['child_id'],
            	'subject_id' => $data['data']['subject_ids'],
            	'stars' => $data['data']['stars'],
            	'stars_number' => $data['data']['stars_number'],
            	'ok_number' => 0,
            	'status' => 0,
            	'reward' => $data['data']['reward_content'],
            	'start_time' => $data['data']['start_time'],
            	'end_time' => $data['data']['end_time'],
            	'add_time' => time(),

            );
            $this->db->insert('zuoye_rewards',$reward_data);

        	echo json_encode(array("code" => 1, "data" => $reward_data));
        }else{
            echo json_encode(array("code" => 404, "data" => 'not user'));
        }

    	/*
    	
    	 {"user_token":{"user_id":"213","token":"P93qQXBlJhfO6w5gELYs1CMQ9TmwJKMY"},"data":{"start_time":"2017-10-27","end_time":"2017-11-27","subject_ids":"34,33,35,43,41,42,40,39,44,38,","stars_number":"80","stars":"5","reward_content":""}} at view/zuoye_reward_add.html:343
    	 */
    }
}